package de.matusystems

class SignUpController {

	def newsletterService

	def index = { log.info("registration controller called") }

	def signup = { SignUpCommand cmd ->
		if (cmd.hasErrors()) {
			render(view: 'index', model:[registrationCommand:cmd])
			return
		}

		def signUp = newsletterService.signUp(cmd.firstname, cmd.lastname, cmd.email)

		[userId:signUp.userId, firstname:cmd.firstname, lastname:cmd.lastname, email:cmd.email]
	}
}

class SignUpCommand {
	String firstname
	String lastname
	String email

	static constraints = {
		firstname(blank: false, minSize: 2)
		lastname(blank: false, minSize: 2)
		email(blank:false, email:true)
	}
}